<?php


class b2c_ctl_wap_agoods extends b2c_ctl_wap_common{  

    function __construct(&$app){
        parent::__construct($app);
      
        $shopname = app::get('wap')->getConf('wap.name');
        $this->shopname =$shopname;
        if(isset($shopname)){
            $this->title = app::get('b2c')->_('樱淘社').'_'.$shopname;
            $this->keywords = app::get('b2c')->_('樱淘社').'_'.$shopname;
            $this->description = app::get('b2c')->_('樱淘社').'_'.$shopname;
        }
        $this->action = $this->_request->get_act_name();
        if(!$this->action) $this->action = 'index';
        $this->pagedata['res_url'] = $this->app->res_url;
        /** end **/
    }
	
	
	
    function info(){
        $goods_id = $_REQUEST['goods_id'];
        $con = $_REQUEST['con'];
        $this->title =$this->shopname ? $this->title : $this->title."樱淘社";
        $this->keywords = $this->shopname? $this->keywords :$this->keywords. "樱淘社";
        $this->description = $this->shopname ?$this->description :  $this->description."樱淘社";
        //$goods_id = $_REQUEST['goods_id'];
        $input['method'] = array("file"=>"mobileapi_rpc_goods","action"=>"get_item");
        $input['data'] = array("iid"=>$goods_id,'son_object'=>'json');
        $goods = $this->getApi($input);
        if(!$goods['status'] || !$goods['data']){
            
            $this->begin(array('app' => 'b2c','ctl' => 'wap_opinions', 'act'=>'index'));
            $this->end(false, app::get('b2c')->_('该商品不存在'));
        }
        if($goods['data']['item']['skus']){
            $goods['data']['item']['skus'] = json_decode($goods['data']['item']['skus'] ,TRUE);
            foreach($goods['data']['item']['skus'] as $k=>$sku){
                $goods['data']['item']['skus'][$k]['endtime'] = date("Y/m/d H:i:s",$sku['endtime']);
				if($sku['is_default']=='true'){
					$def_sku['def_properties']=$sku['properties'];
					$def_sku['def_sku_id']=$sku['sku_id'];
					
				}
				
            }
			
            foreach($goods['data']['item']['skus'] as $k=>$sku){
                $goods['data']['item']['skus'][$k]['endtime'] = date("Y/m/d H:i:s",$sku['endtime']);
				if($sku['is_default']=='true'){
					$default_properties=$sku['properties'];
				}
				
            }
            
            
        }
        
            //商品自定义属性 begin cyky
            $mdl_goods_type_props=app::get('b2c')->model('goods_type_props');
            $goods_type_props=$mdl_goods_type_props->getList('goods_p,name',array('filter_sql'=>'type_id = '.$goods['data']['item']['cid'].' and goods_p in('.$goods['data']['item']['input_pids'].')'),0,-1,'ordernum asc');
            $input_pids_arr=explode(',',$goods['data']['item']['input_pids']);
            $input_str_arr=explode(';',$goods['data']['item']['input_str']);
            foreach($input_pids_arr as $ik=>$pid){
                    foreach($goods_type_props as &$item_prop){
                            if(intval($pid)==intval($item_prop['goods_p'])){
                                    $item_prop['prop_value']=$input_str_arr[$ik];
                            }
                    }
            }
            //商品自定义属性 end cyky
		
		
		

        $input['method'] = array("file"=>"mobileapi_rpc_goods","action"=>"getcomment");
        $input['data'] = array("goods_id"=>$goods_id);
        $opco = $this->getApi($input);
        $goods['data']['item']['brand'] = app::get("b2c")->model("brand")->getRow("*",array('brand_id'=>$goods['data']['item']['brand_id']));
        $input['method'] = array("file"=>"mobileapi_rpc_goods","action"=>"goodslink");
        $input['data'] = array("iid"=>$goods_id);
        $goods_link = $this->getApi($input);
        $goods['data']['item']['goods_link'] = $goods_link['data'];
        //var_dump($goods['data']['item']);exit;
        $this->pagedata['goods'] = $goods['data']['item'];
        $this->pagedata['opco'] = $opco['data'];
        $this->pagedata['con'] = $con;
        $this->pagedata['goods']['props'] = $goods_type_props;
        $this->pagedata['goods']['default_properties'] = explode(';',$default_properties);
        $this->pagedata['sku'] = json_encode($goods['data']['item']['skus']);
        $this->pagedata['def_sku_id'] = json_encode($goods['data']['item']['skus']);
        //var_dump($goods['data']['item']);
//        微信分享
        $this->pagedata['title'] = $goods['data']['item']['title'];
        $this->pagedata['desc'] = $goods['data']['item']['brief'];
        $this->pagedata['link'] = kernel::base_url(1).$this->gen_url(array('app'=>'b2c','ctl'=>'wap_agoods','act'=>'info'))."?goods_id=".$goods_id;
        $this->pagedata['imgUrl'] = $goods['data']['item']['default_img_url'];
		//print_r($this->pagedata['goods']);exit;
        $this->page('wap/agoods/info.html');
        
    }
	
	
	
	
	
}
